//
//  LLRoundRectLabel.swift
//  LaiLang
//
//  Created by David on 2017/2/17.
//  Copyright © 2017年 David. All rights reserved.
//

import UIKit

class LLRoundRectLabel: UILabel {

    override init(frame: CGRect) {
        super.init(frame: frame)
        font = UIFont.systemFont(ofSize: 14)
        textAlignment = .center
        layer.cornerRadius = frame.height / 4
        layer.borderWidth = 1
        
    }
    
    override var font: UIFont!{
        get{
            return super.font
        }
        set(f){
            super.font = f
            text = super.text
        }
    }
    
    override var textColor: UIColor!{
        get{
            return super.textColor
        }
        set(f){
            super.textColor = f
            layer.borderColor = f.cgColor
        }
    }

    
    
    override var text: String?{
        get{
            return super.text
        }
        set(title){
            super.text = title
            if title == nil {
                return
            }
            let width = (title! as NSString).boundingRect(with: CGSize(width: CGFloat(MAXFLOAT), height: frame.height), options: .usesLineFragmentOrigin, attributes: [NSFontAttributeName: font], context: nil).width
            
            frame = CGRect(origin: frame.origin, size: CGSize(width: width + 16, height: frame.height))
            
            
        }
    }
    
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    /*
    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
    }
    */

}
